package model;

import java.util.Random;

import touche.touche.R;
import android.util.Log;
import android.view.View;

public class LevelModel {

	private String _name;
	private boolean _hasMalus;
	private boolean _hasBomb;
	private long _durationLevel;
	private long _durationPicture;
	private Integer[] _picturesInit;
	private Integer[] _pictures;
	private Integer[] _visibles;
	private int _currentPicturePosition;
	private int _scoreByPicture;
	private int _lifeByMissedPicture;
	private int _alertContent;
	private int _alertTitle;

	private Random _random = new Random();

	public LevelModel(String name, boolean hasMalus, boolean hasBomb,
			long durationLevel, long durationPicture, Integer[] picturesInit,
			int picturesCount, int scoreByPicture, int lifeByMissedPicture,
			int alertContent, int alertTitle) {
		super();
		this._name = name;
		this._hasMalus = hasMalus;
		this._hasBomb = hasBomb;
		this._durationLevel = durationLevel;
		this._durationPicture = durationPicture;
		this._picturesInit = picturesInit;
		this._scoreByPicture = scoreByPicture;
		this._lifeByMissedPicture = lifeByMissedPicture;
		this._alertContent = alertContent;
		this._alertTitle = alertTitle;

		// Initialisation des tableaux d'image
		_pictures = new Integer[picturesCount];
		for (int i = 0; i < _pictures.length; i++) {
			_pictures[i] = R.drawable.white;
		}
		_visibles = new Integer[picturesCount];
		for (int i = 0; i < _visibles.length; i++) {
			_visibles[i] = View.INVISIBLE;
		}
	}

	public int getAlertContent() {
		return _alertContent;
	}

	public int getAlertTitle() {
		return _alertTitle;
	}

	public long getDurationLevel() {
		return _durationLevel;
	}

	public long getDurationPicture() {
		return _durationPicture;
	}

	public int getLifeByMissedPicture() {
		return _lifeByMissedPicture;
	}

	public String getName() {
		return _name;
	}

	public Integer[] getPictures() {
		return _pictures;
	}

	public int getScoreByPicture() {
		return _scoreByPicture;
	}

	public Integer[] getVisibles() {
		return _visibles;
	}

	public boolean isHasBomb() {
		return _hasBomb;
	}

	public boolean isHasMalus() {
		return _hasMalus;
	}

	public void shufflePictures() {
		Log.e("LevelModel", "shufflePictures _currentPicturePosition="
				+ _currentPicturePosition);
		_visibles[_currentPicturePosition] = View.INVISIBLE;
		_pictures[_currentPicturePosition] = R.drawable.white;

		int r = _random.nextInt(_visibles.length - 1);
		System.out.println("LevelModel shufflePictures _currentPicturePosition="
				+ _currentPicturePosition + " r=" + r);

		_currentPicturePosition = r;
		_visibles[_currentPicturePosition] = View.VISIBLE;
		_pictures[_currentPicturePosition] = _picturesInit[0];
	}

	public boolean touch(int position) {
		System.out.println("LevelModel touche _currentPicturePosition="
				+ _currentPicturePosition + " position=" + position);
		return _currentPicturePosition == position;
	}

}
